var playScene_layerUI = cc.Layer.extend({
	_winSize:null,
    sprite_bg:null,
    head_bg:null,
    head_img:null,
    s_yao1:null,
    s_yao2:null,
    s_yao3:null,
    s_yao4:null,
    sBtn1:null,
    sBtn2:null,
    sBtn3:null,
    sBtn4:null,
    mHat:null,
    mBody:null,
    mTree:null,
    mBoom:null,
    updateCount:null,
    sBtnNum:null,
    isSBTN:null,
    ctor:function () {
        this._super();
        this._winSize = cc.winSize;

        //背景
        this.sprite_bg = new cc.Sprite(res.bg1_jpg);
        this.sTips = new cc.Sprite(res.tips_png);

        this.sprite_bg.attr({
            x: this._winSize.width / 2,
            y: this._winSize.height / 2,
            scale:1
        });
        this.addChild(this.sprite_bg, 0);

        this.sTips.attr({
            x: this._winSize.width / 2,
            y: this._winSize.height - 300,
            scale:1,
            opacity:0
        });
        this.sTips.runAction(
            cc.sequence(
            	cc.fadeIn(2.0)
        	)
        );
        this.addChild(this.sTips, 0);

        //风铃
        this.s_yao1 = new cc.Sprite(res.yao1_png);
        this.s_yao2 = new cc.Sprite(res.yao2_png);
        this.s_yao3 = new cc.Sprite(res.yao3_png);
        this.s_yao4 = new cc.Sprite(res.yao4_png);

        this.s_yao1.attr({
            x: this._winSize.width - 50,
            y: this._winSize.height,
            scale:1,
            anchorX:0.5,
            anchorY:1
        });
        this.s_yao1.runAction(
            cc.repeatForever(
	            cc.sequence(
	            	cc.rotateTo(0.7, 10).easing(cc.easeOut(0.5)),
	            	cc.rotateTo(0.7, -10).easing(cc.easeOut(0.5))
	        	)
        	)
        );
        this.addChild(this.s_yao1, 0);

        this.s_yao2.attr({
            x: this._winSize.width - 100,
            y: this._winSize.height,
            scale:1,
            anchorX:0.5,
            anchorY:1
        });
        this.s_yao2.runAction(
            cc.repeatForever(
	            cc.sequence(
	            	cc.rotateTo(1, 15).easing(cc.easeOut(0.5)),
	            	cc.rotateTo(1, -15).easing(cc.easeOut(0.5))
	        	)
        	)
        );
        this.addChild(this.s_yao2, 0);

        this.s_yao3.attr({
            x: this._winSize.width - 150,
            y: this._winSize.height,
            scale:1,
            anchorX:0.5,
            anchorY:1
        });
        this.s_yao3.runAction(
            cc.repeatForever(
	            cc.sequence(
	            	cc.rotateTo(1.5, 20).easing(cc.easeOut(0.5)),
	            	cc.rotateTo(1.5, -20).easing(cc.easeOut(0.5))
	        	)
        	)
        );
        this.addChild(this.s_yao3, 0);

        this.s_yao4.attr({
            x: this._winSize.width - 200,
            y: this._winSize.height,
            scale:1,
            anchorX:0.5,
            anchorY:1
        });
        this.s_yao4.runAction(
            cc.repeatForever(
	            cc.sequence(
	            	cc.rotateTo(1.2, 17).easing(cc.easeOut(0.5)),
	            	cc.rotateTo(1.2, -17).easing(cc.easeOut(0.5))
	        	)
        	)
        );
        this.addChild(this.s_yao4, 0);

        //雪人按钮
        var sbody1= cc.MenuItemSprite.create(
            cc.Sprite.create(res.sBody1_png),
            cc.Sprite.create(res.sBody0_png),
            this.goShowText,this);
        var sbody2= cc.MenuItemSprite.create(
            cc.Sprite.create(res.sBody2_png),
            cc.Sprite.create(res.sBody0_png),
            this.goShowText,this);
        var sbody3= cc.MenuItemSprite.create(
            cc.Sprite.create(res.sBody3_png),
            cc.Sprite.create(res.sBody0_png),
            this.goShowText,this);
        var sbody4= cc.MenuItemSprite.create(
            cc.Sprite.create(res.sBody4_png),
            cc.Sprite.create(res.sBody0_png),
            this.goShowText,this);

        this.sBtn1 = cc.Menu.create(sbody1);
        this.sBtn1.attr({
            x: this._winSize.width / 2 - 100,
            y: this._winSize.height - 750,
            scale:1,
            opacity:0
        });
        this.addChild(this.sBtn1, 2);

        this.sBtn2 = cc.Menu.create(sbody2);
        this.sBtn2.attr({
            x: this._winSize.width / 2 + 20,
            y: this._winSize.height - 750,
            scale:1,
            opacity:0
        });
        this.addChild(this.sBtn2, 2);

        this.sBtn3 = cc.Menu.create(sbody3);
        this.sBtn3.attr({
            x: this._winSize.width / 2,
            y: this._winSize.height - 700,
            scale:1,
            opacity:0
        });
        this.addChild(this.sBtn3, 2);

        this.sBtn4 = cc.Menu.create(sbody4);
        this.sBtn4.attr({
            x: this._winSize.width / 2 - 30,
            y: this._winSize.height - 730,
            scale:1,
            opacity:0
        });
        this.addChild(this.sBtn4, 2);

        //开起动画
        this.updateCount = 0;
        this.sBtnNum = 0;
        this.isSBTN = true;
        this.scheduleUpdate();

        //测试自动弹出
        // this.goShowText();

        return true;
    },
    update:function (dt) {
    	if(this.isSBTN){
			this.updateCount += dt;
			if(this.updateCount > 2){
				this.showBtn(this.sBtnNum);
				this.sBtnNum = this.sBtnNum == 3 ? 0 : this.sBtnNum + 1;
				this.updateCount = 0;
			}
    	}
    },
    showBtn:function(num){
    	switch(num){
    		case 0:
    			this.sBtn1.runAction(
		            cc.sequence(
		            	cc.fadeIn(1),
		            	cc.callFunc(this.hideSBtn,this,false)
		        	)
		        );
    			break;
    		case 1:
    			this.sBtn2.runAction(
		            cc.sequence(
		            	cc.fadeIn(1),
		            	cc.callFunc(this.hideSBtn,this,false)
		        	)
		        );
    			break;
    		case 2:
    			this.sBtn3.runAction(
		            cc.sequence(
		            	cc.fadeIn(1),
		            	cc.callFunc(this.hideSBtn,this,false)
		        	)
		        );
    			break;
    		case 3:
    			this.sBtn4.runAction(
		            cc.sequence(
		            	cc.fadeIn(1),
		            	cc.callFunc(this.hideSBtn,this,false)
		        	)
		        );
    			break;
    	}
    },
    hideSBtn:function(obj){
		obj.runAction(
            cc.sequence(
            	cc.fadeOut(0.7)
        	)
        );
    },
    goShowText2:function(){
        this.sTips.runAction(
            cc.sequence(
            	cc.fadeOut(2.0)
        	)
        );

        //圣诞老人
        this.mHat = new cc.Sprite(res.mHat_png);
        this.mBody = new cc.Sprite(res.mBody_png);
        this.mTree = new cc.Sprite(res.tree_png);
        this.mTitle = new cc.Sprite(res.title_png);

        this.mHat.attr({
            x: this._winSize.width / 2 - 157,
            y: this._winSize.height - 713,
            scale:1
        });
        this.mHat.runAction(
            cc.spawn(
            	cc.moveTo(1, cc.p(this._winSize.width / 2,this._winSize.height - 180))
        	)
        );
        this.addChild(this.mHat, 4);

        this.mBody.attr({
            x: this._winSize.width / 2 - 100,
            y: this._winSize.height / 2 - 300,
            scale:1
        });
        this.addChild(this.mBody, 3);

        this.mTree.attr({
            x: this._winSize.width / 2 - 150,
            y: this._winSize.height / 2 - 360,
            scale:0.2,
            anchorX:0.5,
            anchorY:0
        });
        this.mTree.runAction(
            cc.spawn(
            	cc.moveTo(1, cc.p(this._winSize.width / 2,this._winSize.height/2 - 380)),
            	cc.scaleTo(1, 0.9)
        	)
        );
        this.addChild(this.mTree, 2);

        this.mTitle.attr({
            x: this._winSize.width / 2 - 90,
            y: this._winSize.height + 100,
            scale:1
        });
        this.mTitle.runAction(
            cc.sequence(
            	cc.moveTo(1, cc.p(this._winSize.width / 2 - 90,this._winSize.height - 100)),
            	cc.callFunc(this.showDIV,this,false)
        	)
        );
        this.addChild(this.mTitle, 1);
    },
	goShowText:function(){
        if(this.isSBTN){
			this.isSBTN = false;
	        //炸弹
            cc.audioEngine.playEffect(res.boom_mp3);
	        this.mBoom = new cc.Sprite(res.boom_png);
	        this.mBoom.attr({
	            x: this._winSize.width / 2 - 100,
	            y: this._winSize.height / 2 - 300,
	            scale:0.2
	        });
	        this.mBoom.runAction(
	            cc.sequence(
	            	cc.scaleTo(0.3, 1),
	            	cc.fadeOut(.3),
	            	cc.callFunc(this.goShowText2,this,false)
	        	)
	        );
        	this.addChild(this.mBoom, 10);
    	}
	},
	showDIV:function(){
        cc.audioEngine.playMusic(res.bg_mp3, true);
		indexShowDiv();
	}
});